package org.wukongcrm.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.wukongcrm.config.SecurityConfig;
import org.wukongcrm.domain.entity.Menu;
import org.wukongcrm.domain.model.MenuVo;
import org.wukongcrm.domain.model.R;
import org.wukongcrm.service.MenuService;

import java.util.List;

/**
 * @author ZhongWang
 * @since 2025 03 12:08:47
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/menu")
public class MenuController {

    private final MenuService menuService;

    @GetMapping("/first-menu")
    public R<List<Menu>> queryMenuTree(
            @RequestAttribute("userId") Integer userId,
            @RequestParam(value = "isFunction", required = false, defaultValue = "false") Boolean isFunction,
            @RequestParam(value = "id", required = true, defaultValue = "1") Integer id
    ) {
        log.info("userId: {}, isFunction: {}, id: {}", userId, isFunction, id);
        if (userId == SecurityConfig.USER_MANAGER_ID) {
            return R.success(menuService.findFirstMenu(id));
        }
        return null;
    }

}
